package com.example.nft.controller;

import io.swagger.models.auth.In;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DemoTestTeacher {
    static String url = "https://www.61nn.net/";

    public static void main(String[] args) throws IOException {
//        String url2 = "/video/zipai/";
//        String html = getHtml(url+url2);
//        List<String> videoList = getVideoList(html);
//        List<String> videoHtml = getVideoHtml(html);
//        Integer endPage = getEndPage(html, url2);




    }

    public static List<String> getVideoHtml(String html){
        List<String> list = new ArrayList<>();
        Document parse = Jsoup.parse(html);
        Elements elementsByClass = parse.getElementsByClass("preview-item");
        for (Element byClass : elementsByClass) {
            String attr = byClass.select("a").attr("href");
            list.add(attr) ;
        }
        return list;
    }

    public static Integer getEndPage(String html,String name){
        List<String> list = new ArrayList<>();
        Document document = Jsoup.parse(url+html);
        Elements a1 = document.select(".pc_pagination").select("a");
        Element element = a1.get(a1.size() - 1);
        String attr = element.select("a").attr("href");
        attr = attr.replace(".html","").replace("index_","").replace(name,"");

        return Integer.valueOf(attr);
    }


    public static String getHtml(String url) throws IOException {
        return Jsoup.connect(url).execute().body();
    }

    public static List<String> getVideoList(String html){
        List<String> list = new ArrayList<>();
        Document parse = Jsoup.parse(html);
        Elements wrap = parse.getElementsByClass("menu clearfix");
        Element element = wrap.get(0);
        Elements a = element.getElementsByTag("a");
        for (Element element1 : a) {
            String attr = element1.select("a").attr("href");
            list.add(attr);
        }
        return list;
    }

}
